<template>
  <div class="about">
    <h1>表单提交与收集</h1>
    <el-table :data="list" border style="width: 100%">
      <el-table-column prop="pk" label="ID"> </el-table-column>
      <el-table-column prop="fields.book_name" label="书名"> </el-table-column>
      <el-table-column prop="fields.add_time" label="日期"> </el-table-column>
    </el-table>
    <br/>
    <el-input v-model="book_name" placeholder="请输入书籍名称"></el-input>
    <br/>
    <el-button type="success" @click="add">添加</el-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: [],
      book_name:''
    };
  },
  created() {
    this.fetch();
  },
  methods: {
    async fetch() {
      const res = await this.$http.get("/show_books");
      this.list = res.data.list;
      console.log(this.list);
    },
    async add(){
      const res = await this.$http.get(`/add_books?book_name=${this.book_name}`)
      this.book_name = ''
      console.log(res.data)
      this.fetch()
    }
  }
};
</script>
